import 'dart:io';
import 'package:cotton_candy/components/toast.dart';
import 'package:cotton_candy/notifier/tab_notifier.dart';
import 'package:cotton_candy/notifier/theme_notifier.dart';
import 'package:cotton_candy/notifier/user_notifier.dart';
import 'package:cotton_candy/routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';

void main() {
  // 安卓沉浸式状态栏
  if (Platform.isAndroid) {
    SystemChrome.setSystemUIOverlayStyle(
        SystemUiOverlayStyle(statusBarColor: Colors.transparent));
  }
  runApp(new CottonCandyApp());
}

final globalScaffoldKey = GlobalKey<ScaffoldState>();

class CottonCandyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //设置状态栏颜色
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => UserNotifier()),
        ChangeNotifierProvider(create: (_) => TabNotifier()),
        ChangeNotifierProvider(create: (_) => ThemeNotifier()),
      ],
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          hintColor: Colors.black,
          primaryColor: Colors.black,
          pageTransitionsTheme: PageTransitionsTheme(
            builders: <TargetPlatform, PageTransitionsBuilder>{
              TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
              TargetPlatform.android: CupertinoPageTransitionsBuilder(),
            },
          ),
        ),
        builder: (context, child) {
          return Scaffold(
            key: globalScaffoldKey,
            body: ToastProvider(
              child: child,
            ),
          );
        },
        routes: Routes.routes,
      ),
    );
  }
}
